#ifndef FOCUSMEASUREOBJECT_H
#define FOCUSMEASUREOBJECT_H

#include <QObject>
#include <QTimer>
#include <QImage>
#include "FocusMeasure.h"

namespace Qly
{
/**
 * @brief The FocusMeasureObject class 对焦清晰程度评价类
 * 每次新的图片来到后会计算清晰程度。并将计算结果通过 signal 发射出去。
 */
class FocusMeasureObject : public QObject
{
    Q_OBJECT
public:
    explicit FocusMeasureObject(QObject *parent = nullptr);
    void setFocusParameter(FocusMeasure::MeasureMethod method, int factor = 2);

    /**
     * @brief setInterval 变更计算间隔时间。
     * @param ms
     */
    void setInterval(unsigned int ms);

    /**
     * @brief start 为了减少计算量，不是每次来图片都要计算清晰程度。而是每间隔 ms 毫秒计算一次。默认 50ms，也就是每秒输出20次结算结果。
     * @param ms
     */
    void start(unsigned int ms = 50);
    void stop();
public slots:
    void setImage(QImage &colorImage);
signals:
    void focusMeasure(QImage &colorImage, double measure);// 输出当前图像的分值

private slots:
    void on_timeout();
private:
    QTimer * m_pTimer = nullptr;
    FocusMeasure m_focusMeasure;
    unsigned int m_interval = 50;
    bool m_enable = false;
    double m_score = 0;

    bool m_record;
    QImage m_bestImage;
};

}


#endif // FOCUSMEASUREOBJECT_H
